package com.whut.cristiano.autographbook.Activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.whut.cristiano.autographbook.Model.DividerItemDecoration;
import com.whut.cristiano.autographbook.Model.MyCircleAdapter;
import com.whut.cristiano.autographbook.Model.ReceiveCircleAdapter;
import com.whut.cristiano.autographbook.R;
import com.whut.cristiano.autographbook.Util.NetUtil;
import com.whut.cristiano.autographbook.Util.SharedPrefUtil;
import com.whut.cristiano.autographbook.VO.CircleItem;

import java.util.ArrayList;
import java.util.List;

public class ReceiveInfoActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private List<CircleItem> list = new ArrayList<>();
    private ReceiveCircleAdapter adapter;
    private ProgressDialog progressDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receive_info);
        initView();
        refreshData();
    }
    @Override
    public void initView() {
        progressDialog = new ProgressDialog(this);
        recyclerView = (RecyclerView) findViewById(R.id.receive_circle_recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new ReceiveCircleAdapter(list);
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new DividerItemDecoration(this,
                DividerItemDecoration.VERTICAL_LIST));
    }
    /**
     * 显示进度框
     * */
    public void showDialog() {
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setIndeterminate(false);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("正在获取信息...");
        progressDialog.show();
    }
    /**
     * 消失
     * */
    public void dismissDialog() {
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
    }

    private void refreshData(){
        showDialog();
        new Thread(new Runnable() {
            @Override
            public void run() {
                NetUtil.getReceiveInfo(SharedPrefUtil.getUserPhone(),list,adapter,progressDialog);
            }
        }).start();

    }
}
